import requests
import logging

logger = logging.getLogger(__name__)


class Session(requests.Session):
    def request(self, method, url, **kwargs):
        logger.info(f"请求方法：{method}")
        logger.info(f"请求地址：{url}")

        for k, v in kwargs.items():
            logger.info(f"请求参数（{k}）：{v}")

            if k == 'files':
                for name, path in v.items():
                    if isinstance(path, str):
                        v[name] = open(path, "rb")

        ret = super().request(method, url, **kwargs)
        logger.info("---------------")
        logger.info(f"响应状态码：{ret.status_code}")
        logger.info(f"响应头：{ret.headers}")
        logger.info(f"响应正文：{ret.content}")
        return ret
